package com.lxd.filter.Impl;

import com.lxd.common.constants.RabbitMQConstants;
import com.lxd.common.constants.SmsConstant;
import com.lxd.common.enums.ExceptionEnums;
import com.lxd.common.exception.StrategyException;
import com.lxd.common.model.StandardReport;
import com.lxd.common.model.StandardSubmit;
import com.lxd.filter.CheckFilter;
import com.lxd.utils.ErrorSendMsgUtil;
import com.lxd.utils.HutoolDFAUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author Dongdong
 * @注释 基于hutool 工具类 实现 敏感词校验
 */
@Slf4j
@Service(value = "dirtyword")
public class DirtyWordStrategyFilter implements CheckFilter {

    @Autowired
    private ErrorSendMsgUtil errorSendMsgUtil;
    @Override
    public void check(StandardSubmit submit) {
        //1.提取text 并检验
        String text = submit.getText();
        List<String> dirtyWords = HutoolDFAUtil.getDirtyWord(text);
        //2.1 . 存在敏感词
        if (dirtyWords.size() > 0) {
            log.info("【策略模块-敏感词】存在敏感词={}", dirtyWords);
            //3.发送至搜索模块
            log.info("【策略模块】 正在发送至搜索模块", dirtyWords);
            errorSendMsgUtil.sendWriteLog(submit,dirtyWords);
            //4.发送至推送模块
            log.info("【策略模块】 正在发送至推送模块", dirtyWords);
            errorSendMsgUtil.sendPushReport(submit);
            //5.抛出异常，停止检验
            throw new StrategyException(ExceptionEnums.HAVE_DIRTY_WORD);
        }
        //2.2不存在敏感词
        log.info("【策略模块-敏感词】不存在敏感词");
    }
}
